package edu.mju.ddc.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import edu.mju.ddc.domain.Manager;
import edu.mju.ddc.utils.DBUtil;

public class ManagerDaoImpl implements ManagerDao {
	
	private DBUtil dbUtil = DBUtil.getInstance();

	@Override
	public Manager load(String loginId) {
		String sql = "select * from manager where login_id = ?";
		
		PreparedStatement pstmt = dbUtil.getPstmt(sql);
		ResultSet rs = null;
		Manager manager = null;
		try {
			pstmt.setString(1, loginId);
			
			rs = pstmt.executeQuery();
			
			if (rs.next()) {
				manager = new Manager();
				
				manager.setLoginId(rs.getString("login_id"));
				manager.setLoginPwd(rs.getString("login_pwd"));
				manager.setRealName(rs.getString("realname"));
				manager.setStatus(rs.getString("status"));
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
					rs = null;
				}
				if (pstmt != null) {
					pstmt.close();
					pstmt = null;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return manager;
	}

}
